// var i;
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_ShopConfig = require("./AL_GAME_HUA_ShopConfig");
// var AL_GAME_HUA_ShopData = require("./AL_GAME_HUA_ShopData");
// var u = cc._decorator;
// var p = u.ccclass;
// var f = u.property;
// var d =
//     (u.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.bgFrame = null;
//             t.latticeFrame = null;
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.start = function () {
//             AL_APP_SDK_MANAGER.on(AL_GAME_HUA_Define.GameEvent.CHANGE_SHOP_USE, this.refresh, this);
//             this.refresh();
//         };
//         t.prototype.onDestroy = function () {
//             AL_APP_SDK_MANAGER.off(this);
//         };
//         t.prototype.refresh = function () {
//             this.jiazai_beijing_tu();
//             this.jiazai_wangge_tu();
//         };
//         t.prototype.jiazai_beijing_tu = function () {
//             var e = this;
//             return new Promise(function (t, n) {
//                 var o = AL_GAME_HUA_ShopData.ShopData.getInstance().huoqu_shangdian_shifou_zhengzai_shiyong();
//                 var i = AL_GAME_HUA_ShopConfig.ShopConfig.getInstance();
//                 var r = e.bgFrame;
//                 i.jiazai_beijing_pifu(o).then(function (e) {
//                     return e && cc.isValid(r) ? ((r.spriteFrame = e), r.addAutoReleaseAssets(e), t()) : n();
//                 });
//             });
//         };
//         t.prototype.jiazai_wangge_tu = function () {
//             var e = this;
//             return new Promise(function (t, n) {
//                 var o = AL_GAME_HUA_ShopData.ShopData.getInstance().huoqu_shangdian_shifou_zhengzai_shiyong();
//                 var i = AL_GAME_HUA_ShopConfig.ShopConfig.getInstance();
//                 var r = e.latticeFrame;
//                 i.jiazai_shouye_kuang(o).then(function (e) {
//                     return e && cc.isValid(r) ? ((r.spriteFrame = e), r.addAutoReleaseAssets(e), t()) : n();
//                 });
//             });
//         };
//         __decorate([f(cc.Sprite)], t.prototype, "bgFrame", void 0);
//         __decorate([f(cc.Sprite)], t.prototype, "latticeFrame", void 0);
//         return __decorate([p], t);
//     })(cc.Component));
// exports.default = d;


// 引入所需模块
const { GameEvent } = require("./AL_GAME_HUA_Define");
const { ShopData } = require("./AL_GAME_HUA_ShopData");
const { ShopConfig } = require("./AL_GAME_HUA_ShopConfig");
// 从 Cocos Creator 引入装饰器
const { ccclass, property } = cc._decorator;

/**
 * 商店相关类
 */
@ccclass
class ShopComponent extends cc.Component {
    /** 背景框 */
    @property(cc.Sprite)
    bgFrame = null;

    /** 网格框 */
    @property(cc.Sprite)
    latticeFrame = null;

    /** 生命周期开始时调用 */
    start() {
        AL_APP_SDK_MANAGER.on(GameEvent.CHANGE_SHOP_USE, this.refresh, this);
        this.refresh();
    }

    /** 生命周期销毁时调用 */
    onDestroy() {
        AL_APP_SDK_MANAGER.off(this);
    }

    /** 刷新数据 */
    refresh() {
        this.jiazai_beijing_tu();
        this.jiazai_wangge_tu();
    }

    /** 加载背景框 */
    jiazai_beijing_tu() {
        return new Promise((resolve, reject) => {
            const shopUse = ShopData.getInstance().huoqu_shangdian_shifou_zhengzai_shiyong();
            const shopConfig = ShopConfig.getInstance();
            const currentBgFrame = this.bgFrame;
            shopConfig.jiazai_beijing_pifu(shopUse).then((spriteFrame) => {
                if (spriteFrame && cc.isValid(currentBgFrame)) {
                    currentBgFrame.spriteFrame = spriteFrame;
                    currentBgFrame.addAutoReleaseAssets(spriteFrame);
                    resolve();
                } else {
                    reject();
                }
            });
        });
    }

    /** 加载网格框 */
    jiazai_wangge_tu() {
        return new Promise((resolve, reject) => {
            const shopUse = ShopData.getInstance().huoqu_shangdian_shifou_zhengzai_shiyong();
            const shopConfig = ShopConfig.getInstance();
            const currentLatticeFrame = this.latticeFrame;
            shopConfig.jiazai_shouye_kuang(shopUse).then((spriteFrame) => {
                if (spriteFrame && cc.isValid(currentLatticeFrame)) {
                    currentLatticeFrame.spriteFrame = spriteFrame;
                    currentLatticeFrame.addAutoReleaseAssets(spriteFrame);
                    resolve();
                } else {
                    reject();
                }
            });
        });
    }
}

// 导出类
exports.default = ShopComponent;